package com.caroil.caroilservice.activitys;

import android.content.Intent;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;

import com.caroil.caroilservice.R;
import com.caroil.caroilservice.activitys.login.LoginAc;
import com.caroil.caroilservice.base.BaseActivity;
import com.caroil.caroilservice.base.ConfigureFile;
import com.caroil.caroilservice.util.SPUtil;

import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import cn.ycbjie.ycstatusbarlib.utils.StatusBarUtils;

/**
 * 启动页
 */
public class SplashAc extends BaseActivity {
    private static final int SPLASH_TIME = 3000;
    private View mFlashView;

    @Override
    protected int bindLayout() {
        return R.layout.ac_splash;
    }

    @Override
    protected void initView() {
        setBarState();
        mFlashView = findViewById(R.id.flash_view);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void loadMethod() {
        handleData();
    }

    private void handleData() {
        mFlashView.postDelayed(() -> {
            if (SPUtil.getInstance().getBoolean(ConfigureFile.ISLOGIN, false))
                startLogin();
            else
                startLogin();
        }, SPLASH_TIME);
    }

    private void startLogin() {
        Intent intent = new Intent(SplashAc.this, LoginAc.class);
        startActivity(intent);
        overridePendingTransition(0, 0);
        finish();
    }

    private void startMain() {
//        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
////        startActivity(intent);
////        overridePendingTransition(0, 0);
////        finish();

    }
    /**
     * 设置顶部状态栏颜色和字体颜色
     */
    public void setBarState() {
        Window window = getWindow();
        View decorView = window.getDecorView();
        decorView.setOnApplyWindowInsetsListener((v, insets) -> {
            WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
            return defaultInsets.replaceSystemWindowInsets(
                    defaultInsets.getSystemWindowInsetLeft(),
                    0,
                    defaultInsets.getSystemWindowInsetRight(),
                    defaultInsets.getSystemWindowInsetBottom());
        });
        ViewCompat.requestApplyInsets(decorView);
        //将状态栏设成透明，如不想透明可设置其他颜色
        window.setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
        //状态栏亮色模式，设置状态栏黑色文字、图标
        StatusBarUtils.StatusBarLightMode(this);
    }


}
